package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class JDBCDemo8 {
    public static void main(String[] args) {
        UserInfo ui = InputUtil.getInputObject(new UserInfo(), "欢迎注册", "注册");
        try (Connection connection = DBUtil.getConnection())
        {
            String sql="insert into userinfo(username,password,nickname,age) " +
                    "values(?,?,?,?)";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,ui.getUsername());
            ps.setString(2,ui.getPassword());
            ps.setString(3,ui.getNickname());
            ps.setInt(4,ui.getAge());
            int num=ps.executeUpdate();
            if(num>0)
                System.out.println("注册成功");
            else
                System.out.println("注册失败");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
